package common;

import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;

// 网站域名 联系电话 手机号码 邮政编码 邮箱
public class RegexVerifyUtils {

	/**
	 * 正则验证方法
	 * 
	 * @param regexstr
	 * @param str
	 * @return
	 */
	public static boolean Match(String regexstr, String str) {
		Pattern regex = Pattern.compile(regexstr, Pattern.CASE_INSENSITIVE
				| Pattern.DOTALL);
		Matcher matcher = regex.matcher(str);
		return matcher.matches();
	}

	/**
	 * 邮箱验证
	 * 
	 * @param mail
	 * @return
	 */
	public static boolean MatchMail(String mail) {
		String mailregex = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
		return Match(mailregex, mail);
	}

	/**
	 * 手机验证
	 * 
	 * @param mobile
	 * @return
	 */
	public static boolean MatchMobile(String mobile) {
		String mobileregex = "^(13[4,5,6,7,8,9]|15[0,8,9,1,7]|188|187)\\d{8}$";
		return Match(mobileregex, mobile);
	}

	/**
	 * 电话验证
	 * 
	 * @param Tel
	 * @return
	 */
	public static boolean MatchTel(String Tel) {
		String telregex = "(^[0-9]{3,4}-[0-9]{7,8}-[0-9]{3,4}$)|(^[0-9]{3,4}-[0-9]{7,8}$)|(^[0-9]{7,8}-[0-9]{3,4}$)|(^[0-9]{7,15}$)";
		return Match(telregex, Tel);
	}
	/**
	 * 主域名验证
	 * 
	 * @param Tel
	 * @return
	 */
	public static boolean MatchWebDoMain(String webdomain) {
		String webdomainregex = "https?://([^/]+)/*";
		return Match(webdomainregex, webdomain);
	}

	public static boolean MatchZipCode(String zipcode) {
		String zipcoderegex = "^[0-9]{6}$";
		return Match(zipcoderegex, zipcode);
	}


	public static void main(String[] args) {
		// 电子邮件
		 System.out.println(MatchMail("dffdfdf@qq.com"));
		 System.out.println(MatchMobile("14533164369"));
		 System.out.println(MatchWebDoMain("https://www.nihao/ddcom"));
	}

}
